home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDTime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.8 KB  |  168 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDTime - An XFCN to report a variety of relevant times
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDTime.c
  11.     link -sn Main=CDTime -sn STDIO=CDTime ∂
  12.          -sn INTENV=CDTime -rt XFCN=42 ∂
  13.          -m CDTime CDTime.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27.  
  28. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  29.  
  30.  
  31. /************************************************************************
  32.  *
  33.  *  Function:        CDTime
  34.  *
  35.  *  Purpose:        return several different times relevant to this disc
  36.  *
  37.  *  Returns:        a comma separated list, or an error
  38.  *                    if it's a negative number, it's an error
  39.  *                    if we return nothing, wrong number of parameters
  40.  *                    were specified.
  41.  *
  42.  *                    The list contains 15 items:
  43.  *                    Items 1, 2, 3 are elapsed time, current track
  44.  *                    Items 4, 5, 6 are remaining time, current track
  45.  *                    Items 7, 8, 9 are elapsed time on disc
  46.  *                    Items 10, 11, 12 are remaining time on disc
  47.  *                    Items 13, 14, 15 are total run time on disc
  48.  *                    all times are absolute minute, second and block.
  49.  *
  50.  *  Side Effects:
  51.  *
  52.  *  Description:    We need no parameter:
  53.  *                    Get the ioRefNum that we got from previously calling
  54.  *                    CDOpen() by accessing a famous global
  55.  *
  56.  ************************************************************************/
  57. pascal void
  58. CDTime(paramPtr)
  59. XCmdBlockPtr    paramPtr;
  60. {
  61.     Str255    returnString;
  62.     OSErr    result;
  63.     short    ioRefNum;
  64.     Handle    refHandle;
  65.     long    trackNo;
  66.     long    currentMinute, currentSecond, currentBlock;    /* current spot */
  67.     long    startMinute, startSecond, startBlock;        /* start of track */
  68.     long    elapsedMinute, elapsedSecond, elapsedBlock;    /* used up */
  69.     long    remainMinute, remainSecond, remainBlock;    /* remaining */
  70.     long    remainDiscMinute, remainDiscSecond, remainDiscBlock;
  71.     long    totalDiscMinute, totalDiscSecond, totalDiscBlock;
  72.     long    args[15];
  73.     
  74.     /* Must be no parameter */
  75.     if ((paramPtr->paramCount) != 0)
  76.     {
  77.         /* Report error in parameters by returning -1 */
  78.         NumToStr(paramPtr, (long) -1, &returnString);
  79.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  80.         return;
  81.     }
  82.     
  83.     /* Get the global ioRefNum and convert it. */
  84.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  85.     ioRefNum = atoi(*(refHandle));
  86.     DisposHandle(refHandle);
  87.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  88.     
  89.     result = ReadQ(ioRefNum, &trackNo, ¤tMinute, ¤tSecond, ¤tBlock);
  90.     
  91.     if (result == noErr)
  92.         result = TrackStart(ioRefNum, trackNo+1, &remainMinute, &remainSecond, &remainBlock);
  93.     
  94.     if (result != noErr)    /* we specified an invalid track. Use disc time */
  95.         result = DiscTime(ioRefNum, &remainMinute, &remainSecond, &remainBlock);
  96.     
  97.     if (result == noErr)
  98.     {
  99.         TimeDiff(&remainMinute, &remainSecond, &remainBlock,
  100.                  remainMinute, remainSecond, remainBlock,
  101.                  currentMinute, currentSecond, currentBlock);
  102.     }
  103.     
  104.     if (result == noErr)
  105.         result = TrackStart(ioRefNum, trackNo, &startMinute, &startSecond, &startBlock);
  106.     
  107.     if (result == noErr)
  108.     {
  109.         TimeDiff(&elapsedMinute, &elapsedSecond, &elapsedBlock,
  110.                  currentMinute, currentSecond, currentBlock,
  111.                  startMinute, startSecond, startBlock);
  112.     }
  113.  
  114.     if (result == noErr)
  115.         result = DiscTime(ioRefNum, &totalDiscMinute, &totalDiscSecond, &totalDiscBlock);
  116.  
  117.     if (result == noErr)
  118.     {
  119.         TimeDiff(&remainDiscMinute, &remainDiscSecond, &remainDiscBlock,
  120.                  totalDiscMinute, totalDiscSecond, totalDiscBlock,
  121.                  currentMinute, currentSecond, currentBlock);
  122.     }
  123.     
  124.     if (result == noErr)
  125.     {
  126.         TimeDiff(&totalDiscMinute, &totalDiscSecond, &totalDiscBlock,
  127.                   totalDiscMinute, totalDiscSecond, totalDiscBlock,
  128.                   0, 0, 1);        /* report time as 1 block less than actual */
  129.     }
  130.         
  131.     
  132.     args[0] = elapsedMinute; 
  133.     args[1] = elapsedSecond; 
  134.     args[2] = elapsedBlock;
  135.     args[3] = remainMinute; 
  136.     args[4] = remainSecond; 
  137.     args[5] = remainBlock;
  138.     args[6] = currentMinute; 
  139.     args[7] = currentSecond; 
  140.     args[8] = currentBlock;
  141.     args[9] = remainDiscMinute; 
  142.     args[10] = remainDiscSecond; 
  143.     args[11] = remainDiscBlock;
  144.     args[12] = totalDiscMinute; 
  145.     args[13] = totalDiscSecond; 
  146.     args[14] = totalDiscBlock;
  147.  
  148.     FormatString(&returnString, args, 15);
  149.         
  150.     if (result == noErr)
  151.     {
  152.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  153.     }
  154.     else
  155.     {
  156.         /* We got an error. Convert result to string & return it as error */
  157.         NumToStr(paramPtr, (long) result, &returnString);
  158.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  159.     }
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166. /* C routines for HyperCard callbacks */
  167. #include <XCmdGlue.inc.c>
  168.